/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package clip.gui;

import clip.model.Buddy;
import java.awt.Color;
import java.awt.Component;
import java.awt.Font;
import java.awt.Graphics;
import javax.swing.BorderFactory;
import javax.swing.JCheckBox;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.ListCellRenderer;
import javax.swing.border.BevelBorder;

/**
 *
 * @author admin
 */
class BuddyListCellRenderer extends JLabel implements ListCellRenderer {
    Color onlineStatusColor=Color.GRAY;
    public BuddyListCellRenderer() {
        setOpaque(true);
        JCheckBox jBox = new JCheckBox("test", true);
        this.add(jBox);
        this.validate();
        
    }

    @Override
    protected void paintComponent(Graphics g) {
        super.paintComponent(g);
        
        g.setColor(onlineStatusColor);
        g.fillOval(this.getWidth()-20, 3, 15, 15);
        
    }

    public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
        Buddy b = (Buddy) value;
        String connectedString ="";
        if (b.getStatus().equals(Buddy.CONNECTIONSTATUS.CONNECTED)) {
            connectedString="(connected)";
            onlineStatusColor=Color.green;
        } else if (b.getStatus().equals(Buddy.CONNECTIONSTATUS.CONNECTING)) {
            connectedString="(connecting)";
            onlineStatusColor=Color.white;
        } else if (b.getStatus().equals(Buddy.CONNECTIONSTATUS.DISCONNECTED)) {
            connectedString="(disconnected)";
            onlineStatusColor=Color.gray.darker();
        }
        
        setText(b.getNickname() + connectedString);
        setToolTipText(b.getNickname() + "@" + b.getHostname() + ":" + b.getPort()+ " ::: "+ connectedString);
        Font font = new Font("Arial", Font.BOLD, 14);
        setFont(font);
        this.setBorder(BorderFactory.createBevelBorder(BevelBorder.RAISED));
        this.setForeground(Color.WHITE);
        if (isSelected) {
            this.setBackground(Color.GRAY.darker());
        // unselected, and not the DnD drop location
        } else {
            this.setBackground(Color.GRAY);
        }

        return this;
    }
}

